home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tex / style / misc / shading.sty < prev    next >
Text File  |  1995-11-25  |  7KB  |  176 lines

  1. %% Save file as: SHADING.STY                    Source: FILESERV@SHSU.BITNET
  2. %From:  IN%"LEO@vaxc.cc.monash.edu.au"  7-JAN-1992 01:27:46.65
  3. %Modified to work as a LaTeX style: mroth@afit.af.mil 22 Jan 92
  4. %  -- added setting the grayscale as an optional argument.
  5. %  -- allowed multiple paragraphs in the \parashade command
  6. %  USAGE: \textshade[grayscale]{corneroption}{text to be shaded}
  7. %         \parashade[grayscale]{corneroption}{paragraph(s) to be shaded}
  8. %         where
  9. %         grayscale is a number from 0 to 1, the higher the number the
  10. %                   lighter the shading, if missing it is set to 0.95
  11. %         corneroption is either sharpcorners or roundcorners
  12. %
  13. %  LIMITATIONS: --can not break the shaded text across lines (\textshade) or
  14. %                 across pages (both)
  15. %               --can not specify the line width of the surrounding box or
  16. %                 the amount of space between the surrounding
  17. %                 box and the text to be shaded as arguments
  18. %               --modifying the xgrayspace and ygrayspace in the argument
  19. %                 will only affect the space added to the right and
  20. %                 bottom of the box, respectively
  21. %
  22. %  EXAMPLES:
  23. %    This is a test of a\ \textshade[1]{roundcorners}{shaded box} routine.
  24. %    With a grayscale of 1, we essentially get no shading, and just a box.
  25. %
  26. %    This is another test of a\ \textshade{sharpcorners}{shaded box} routine.
  27. %    The default shading of .95 is used here.
  28. %
  29. %    \parashade[.995]{roundcorners}{\gdef\linewidth{.5}%
  30. %    This is one very long line which I expect will be broken over one or more
  31. %    lines. The idea is to have this paragraph enclosed in a shaded box. I'll
  32. %    just keep on typing until I can be sure that there are more than two lines
  33. %    in this paragraph. I expect that this should be well and truely sufficient
  34. %    to test this macro.
  35. %    } %This shows an example of changing the linewidth used, without
  36. %      %changing the style
  37. %
  38. %    The field equations of General Relativity are\ %
  39. %%
  40. %    \textshade{roundcorners}{\hbox{$G_{\mu\nu} = kT_{\mu\nu}$}}
  41. %
  42. %    They can also be written as
  43. %
  44. %    \parashade{sharpcorners}{$$R_{\mu\nu}-{1\over2}g_{\mu\nu}R = kT_{\mu\nu}$$}
  45. %
  46. %----------------------------------------------------------------------------
  47. \newbox\graybox
  48. \newdimen\xgrayspace
  49. \newdimen\ygrayspace
  50. %----------------------------------------------------------------------------
  51. %
  52. % The following \TeX code was based on previous work by
  53. %
  54. %            Je'ro^me Maillot, maillot@bora.inria.fr
  55. %
  56. %----------------------------------------------------------------------------
  57. %
  58. % Use the following for one or more words within a line.
  59. %
  60. %MAR-added ability for optional argument for user to set grayscale
  61. \def\textshade{\@ifnextchar[{\@textshade}{\@textshade[0.95]}}
  62. \def\@textshade[#1]#2#3{%
  63.     \xgrayspace=4pt%
  64.     \ygrayspace=4pt%
  65.     \def\grayshade{#1}%
  66.     \def\linewidth{1}%
  67.     \def\theradius{5}%
  68.     \setbox\graybox=\hbox{\surroundboxa{#3}}%
  69.     \hbox{%
  70.     \hbox to 0pt{%
  71.     \special{"gsave newpath 0 0 moveto                                %
  72.         0                                    1 copy /xmin exch store  %
  73.         \number\dp\graybox \space -65536 div 1 copy /ymin exch store  %
  74.         \number\wd\graybox \space  65536 div 1 copy /xmax exch store  %
  75.         \number\ht\graybox \space  65536 div 1 copy /ymax exch store  %
  76.         \theradius\space                            /radius exch store
  77.         \linewidth\space                            /linewidth exch store
  78.         \grayshade\space                            /grayshade exch store
  79.         #2 grestore}}%
  80.     \box\graybox}}%
  81. %
  82. % Use the following for paragraphs.
  83. %
  84. %MAR-added ability for optional argument for user to set grayscale
  85. \def\parashade{\@ifnextchar[{\@parashade}{\@parashade[0.95]}}
  86. %MAR-added \long to allow multiple paragraphs in one shaded block
  87. \long\def\@parashade[#1]#2#3{%
  88.     \xgrayspace=10pt%
  89.     \ygrayspace=10pt%
  90.     \def\grayshade{#1}%
  91.     \def\linewidth{2}%
  92.     \def\theradius{10}%
  93.     \def\thevskip{15pt}%
  94.     \setbox\graybox=\hbox{\surroundboxb{#3}}%
  95.     \vskip\thevskip
  96.     \hbox{%
  97.     \hbox to 0pt{%
  98.     \special{"gsave newpath 0 0 moveto                                %
  99.         0                                    1 copy /xmin exch store  %
  100.         \number\dp\graybox \space -65536 div 1 copy /ymin exch store  %
  101.         \number\wd\graybox \space  65536 div 1 copy /xmax exch store  %
  102.         \number\ht\graybox \space  65536 div 1 copy /ymax exch store  %
  103.         \theradius\space                            /radius exch store
  104.         \linewidth\space                            /linewidth exch store
  105.         \grayshade\space                            /grayshade exch store
  106.         #2 grestore}}%
  107.      \box\graybox}%
  108.      \vskip\thevskip%
  109. }%
  110. %----------------------------------------------------------------------------
  111. %
  112. % A pair of box macros. Each builds a slightly oversized box
  113. % containing the text. The text is centred both in the vertical
  114. % horizontal directions.
  115. %
  116. % Use the following for one or more words within a line.
  117. %
  118. \long\def\surroundboxa#1{\leavevmode\hbox{\vtop{%
  119. \vbox{\kern\ygrayspace%
  120. \hbox{\kern\xgrayspace#1%
  121.       \kern\xgrayspace}}\kern\ygrayspace}}}
  122. %
  123. % Use the following for a paragraphs.
  124. %
  125. \long\def\surroundboxb#1{\leavevmode\hbox{\vtop{%
  126. \vbox{\kern\ygrayspace%
  127. \hbox{\kern\xgrayspace\vbox{\advance\hsize-2\xgrayspace#1}%
  128.       \kern\xgrayspace}}\kern\ygrayspace}}}
  129. %----------------------------------------------------------------------------
  130. %
  131. % Here are some simple PostScript routines.
  132. %
  133. % The TeX command \PScommands must be called before any of the
  134. % shading routines can be used.
  135. %
  136. \long\def\PScommands{\special{! TeXDict begin
  137. %
  138. /sharpbox{%
  139.            newpath
  140.            xmin ymin moveto
  141.            xmin ymax lineto
  142.            xmax ymax lineto
  143.            xmax ymin lineto
  144.            xmin ymin lineto
  145.            closepath
  146.           }bind def
  147. %
  148. /roundbox{%
  149.            newpath
  150.            xmin radius add ymin moveto
  151.            xmax ymin xmax ymax radius arcto
  152.            xmax ymax xmin ymax radius arcto
  153.            xmin ymax xmin ymin radius arcto
  154.            xmin ymin xmax ymin radius arcto 16 {pop} repeat
  155.            closepath
  156.           }bind def
  157. %
  158. /sharpcorners{%
  159.                sharpbox gsave grayshade setgray fill grestore
  160.                linewidth setlinewidth stroke
  161.               }bind def
  162. %
  163. /plainbox{%
  164.            sharpbox grayshade setgray fill
  165.           }bind def
  166. %
  167. /roundcorners{%
  168.                roundbox gsave grayshade setgray fill grestore
  169.                linewidth setlinewidth stroke
  170.               }bind def
  171. %
  172. end}%                   Closes dictionnary
  173. }%
  174.  
  175. \PScommands
  176.